all:
	bash po/gen_mo.sh
	wget https://www.atzlinux.com/allpackages-x86_64-v12-section.json -O debian/allpackages.json
clean:
	rm -fv debian/allpackages.json
	rm -rfv usr/share/locale env
env:
	python3 -m venv env --system-site-packages
	ln -s ../../../usr/lib/python3/dist-packages env/lib/*/
run:
	python3 usr/share/atzlinux-store/atzlinux-store-ui.py
changelog:
	git log --oneline --decorate --since="$(shell head -n 1 debian/changelog | grep -o '[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}' || echo '2024-06-01')" --pretty=format:"  * %s" > /tmp/changelog_entries.txt
	@if [ -s /tmp/changelog_entries.txt ]; then \
		echo "更新 debian/changelog 包含新的 git 提交记录"; \
		VERSION=$$(dpkg-parsechangelog -S Version | awk -F. '{$$NF=$$NF+1; print}' OFS='.'); \
		echo "atzlinux-store ($$VERSION) unstable; urgency=medium" > debian/changelog.new; \
		echo "" >> debian/changelog.new; \
		cat /tmp/changelog_entries.txt >> debian/changelog.new; \
		echo "" >> debian/changelog.new; \
		echo " -- $$(git config user.name) <$$(git config user.email)>  $$(date -R)" >> debian/changelog.new; \
		echo "" >> debian/changelog.new; \
		cat debian/changelog >> debian/changelog.new; \
		mv debian/changelog.new debian/changelog; \
	else \
		echo "没有新的 git 提交记录，跳过 changelog 更新"; \
	fi
	@rm -f /tmp/changelog_entries.txt
package: changelog
	debuild -b
